package com.feiyi.app.adapter;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.feiyi.app.R;
import com.feiyi.app.bean.OrderListBean;
import com.feiyi.app.glideutils.GlideImgManager;

import java.util.List;

/**
 * @author wangliantao
 * @time 2018 12 2018/12/9 12:43 PM
 * @email 1346947404@qq.com
 * @package com.feiyi.app.adapter
 * @describe： In me the tiger sniffs the rose
 */
public class MyOrderListAdapter extends BaseQuickAdapter<OrderListBean.DataBean,BaseViewHolder> {

    public MyOrderListAdapter(int layoutResId, @Nullable List<OrderListBean.DataBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, OrderListBean.DataBean item) {

        ImageView imageView1 = helper.getView(R.id.iv_orderlist_1);
        ImageView imageView2 = helper.getView(R.id.iv_orderlist_2);
        ImageView imageView3 = helper.getView(R.id.iv_orderlist_3);

        if (item.getType().equals("await_pay")){//await_pay 待付款 await_ship 待发货 shipped 待收货 finished 历史订单 all 全部订单


            helper.setText(R.id.tv_order_type,"等待付款")
                    .setText(R.id.tv_orderlist_count,"共"+item.getGoods_list().size()+"件商品")
                    .setText(R.id.tv_orderlist_price,"需付款： "+item.getTotal_fee())
                    .setText(R.id.tv_orderlist_to_pay,"去付款");
            if (item.getGoods_list().size()==1){
                imageView1.setVisibility(View.VISIBLE);
                GlideImgManager.loadImage(mContext,item.getGoods_list().get(0).getImg().getThumb(),imageView1);
                imageView2.setVisibility(View.GONE);
                imageView3.setVisibility(View.GONE);
            }else if (item.getGoods_list().size() == 2){
                imageView1.setVisibility(View.VISIBLE);
                imageView2.setVisibility(View.VISIBLE);
                GlideImgManager.loadImage(mContext,item.getGoods_list().get(0).getImg().getThumb(),imageView1);
                GlideImgManager.loadImage(mContext,item.getGoods_list().get(1).getImg().getThumb(),imageView2);
                imageView3.setVisibility(View.GONE);
            }else {
                imageView1.setVisibility(View.VISIBLE);
                imageView2.setVisibility(View.VISIBLE);
                imageView3.setVisibility(View.VISIBLE);
                GlideImgManager.loadImage(mContext,item.getGoods_list().get(0).getImg().getThumb(),imageView1);
                GlideImgManager.loadImage(mContext,item.getGoods_list().get(1).getImg().getThumb(),imageView2);
                GlideImgManager.loadImage(mContext,item.getGoods_list().get(2).getImg().getThumb(),imageView3);
            }
            helper.setVisible(R.id.tv_orderlist_desc,false)
                    .setVisible(R.id.tv_orderlist_to_praise,false)
                    .setVisible(R.id.tv_orderlist_to_pay,true);
            helper.addOnClickListener(R.id.tv_orderlist_to_pay);

        }else if (item.getType().equals("shipped")){
            helper.setText(R.id.tv_order_type,"等待收货")
                    .setText(R.id.tv_orderlist_count,"共"+item.getGoods_list().size()+"件商品")
                    .setText(R.id.tv_orderlist_price,"需付款： "+item.getTotal_fee())
                    .setText(R.id.tv_orderlist_to_pay,"再次购买");
            if (item.getGoods_list().size() >=1 ){
                helper.setText(R.id.tv_orderlist_desc,item.getGoods_list().get(0).getName()+"等");
                imageView1.setVisibility(View.VISIBLE);
                GlideImgManager.loadImage(mContext,item.getGoods_list().get(0).getImg().getThumb(),imageView1);
                imageView2.setVisibility(View.GONE);
                imageView3.setVisibility(View.GONE);
            }
            helper.setVisible(R.id.tv_orderlist_desc,true)
                    .setVisible(R.id.tv_orderlist_to_praise,true)
                    .setVisible(R.id.tv_orderlist_to_pay,true);
            helper.addOnClickListener(R.id.tv_orderlist_to_pay)
                    .addOnClickListener(R.id.tv_orderlist_to_praise);

        }else if (item.getType().equals("finished")){
            helper.setText(R.id.tv_order_type,"等待评价")
                    .setText(R.id.tv_orderlist_count,"共"+item.getGoods_list().size()+"件商品")
                    .setText(R.id.tv_orderlist_price,"需付款： "+item.getTotal_fee())
                    .setText(R.id.tv_orderlist_to_pay,"再次购买");
            if (item.getGoods_list().size() >=1 ){
                helper.setText(R.id.tv_orderlist_desc,item.getGoods_list().get(0).getName()+"等");
                imageView1.setVisibility(View.VISIBLE);
                GlideImgManager.loadImage(mContext,item.getGoods_list().get(0).getImg().getThumb(),imageView1);
                imageView2.setVisibility(View.GONE);
                imageView3.setVisibility(View.GONE);
            }
            helper.setVisible(R.id.tv_orderlist_desc,true)
                    .setVisible(R.id.tv_orderlist_to_praise,true)
                    .setVisible(R.id.tv_orderlist_to_pay,true);
            helper.addOnClickListener(R.id.tv_orderlist_to_pay)
                    .addOnClickListener(R.id.tv_orderlist_to_praise);
        }else {
            helper.setText(R.id.tv_order_type,"");
            helper.setBackgroundRes(R.id.tv_order_type,R.mipmap.shangchu);
            helper.addOnClickListener(R.id.tv_order_type);
            helper.setText(R.id.tv_orderlist_count,"共"+item.getGoods_list().size()+"件商品")
                    .setText(R.id.tv_orderlist_price,"需付款： "+item.getTotal_fee())
                    .setText(R.id.tv_orderlist_to_pay,"再次购买");
            if (item.getGoods_list().size() >=1 ){
                helper.setText(R.id.tv_orderlist_desc,item.getGoods_list().get(0).getName()+"等");
                imageView1.setVisibility(View.VISIBLE);
                GlideImgManager.loadImage(mContext,item.getGoods_list().get(0).getImg().getThumb(),imageView1);
                imageView2.setVisibility(View.GONE);
                imageView3.setVisibility(View.GONE);
            }
            helper.setVisible(R.id.tv_orderlist_desc,true)
                    .setVisible(R.id.tv_orderlist_to_praise,true)
                    .setVisible(R.id.tv_orderlist_to_pay,true);
            helper.addOnClickListener(R.id.tv_orderlist_to_pay)
                    .addOnClickListener(R.id.tv_orderlist_to_praise)
                    .addOnClickListener(R.id.tv_order_type);
        }




    }
}
